import com.itheima.Mapper.BrandMapper;
import com.itheima.Mapper.CustomerMapper;
import com.itheima.Mapper.User2Mapper;
import com.itheima.Mapper.UserMapper;
import com.itheima.pojo.*;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MybatisDemo {
    public static void main(String[] args) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        //2.获取sqlsession对象
        SqlSession sqlSession = sqlSessionFactory.openSession();
        User2Mapper user2Mapper = sqlSession.getMapper(User2Mapper.class);
//        User user = userMapper.selectById(1);
//        System.out.println(user);
//        User user2=userMapper.selectByP("zhangsan","男","北京");
//        System.out.println(user2);
//        userMapper.Insert("zhangwu","123456","女","长春");
//        sqlSession.commit();
//        User2 user2=user2Mapper.selectById(1);
//        System.out.println(user2);

        CustomerMapper customerMapper=sqlSession.getMapper(CustomerMapper.class);
        Customer c = customerMapper.findById(1);
        List<Order> orders = c.getOrders();
        for(Order o:orders){
            System.out.println(o.toString());
        }
//        BrandMapper brandMapper=sqlSession.getMapper(BrandMapper.class);
//        List<Brand> brands=brandMapper.selectAll();
//        System.out.println(brands);
        sqlSession.close();
    }
}
